package com.sise.aio和bio和nio.bio.bio2;

import lombok.extern.slf4j.Slf4j;


import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author idea
 * @data 2019/1/20
 */
@Slf4j
public class Server {

    private ServerSocket serverSocket;

    private static BufferedReader bufferedReader;

    private static PrintWriter printWriter;

    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(1001);
            Socket socket = serverSocket.accept();
            System.out.println("获取链接成功！");
            bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            printWriter = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));

            String content = bufferedReader.readLine();
            System.out.println("client 发送的数据：" + content);
            printWriter.println("thanks you!");
            printWriter.flush();

        } catch (IOException e) {
            log.error("[Server] exception is :",e);
        }
    }

}
